package com.jingdianjichi.auth.domain.service.impl;

import com.jingdianjichi.auth.common.enums.IsDeletedFlagEnum;
import com.jingdianjichi.auth.domain.entity.AuthRolePermissionBO;
import com.jingdianjichi.auth.domain.service.AuthRolePermissionDomainService;
import com.jingdianjichi.auth.infra.basic.entity.AuthRolePermission;
import com.jingdianjichi.auth.infra.basic.service.AuthRolePermissionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * AuthRolePermissionDomainServiceImpl 类
 *
 * @author 熊苏鹏1
 * @date 2025/3/2 20:07
 * @description
 */
@Service
public class AuthRolePermissionDomainServiceImpl implements AuthRolePermissionDomainService {
    @Resource
    private AuthRolePermissionService authRolePermissionService;
    @Override
    public Boolean add(AuthRolePermissionBO authPermissionBO) {
        List<AuthRolePermission> authRolePermissions = new ArrayList<>();
        authPermissionBO.getPermissionIdList().forEach(permissionId -> {
            AuthRolePermission authRolePermission = new AuthRolePermission();
            authRolePermission.setRoleId(authPermissionBO.getRoleId());
            authRolePermission.setPermissionId(permissionId);
            authRolePermission.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
            authRolePermissions.add(authRolePermission);
        });
        authRolePermissionService.insertBatch(authRolePermissions);
        return true;

    }
}
